//
//  MainViewController.m
//  UI09_2_自定义cell
//
//  Created by Scott on 15/5/7.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "MainViewController.h"
#import "Mycell1.h"
#import "Mycell2.h"

@interface MainViewController () <UITableViewDataSource>

@property (nonatomic, retain) NSMutableArray *arr;

@end

@implementation MainViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.arr = [NSMutableArray arrayWithObjects:@"北京", @"河北", @"河南", @"黑龙江", @"吉林", @"辽宁", @"天津", nil];
        
    }
    return self;
}

- (void)dealloc
{
    [_arr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TableView";
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    [self.view addSubview:tableView];
    [tableView release];
    
    tableView.dataSource = self;
    

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    switch (indexPath.row) {
        case 0:
        case 1:
        {
            static NSString *indenti = @"reuse1";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indenti];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indenti] autorelease];
            }
            
            cell.textLabel.text = [self.arr objectAtIndex:indexPath.row];
            cell.detailTextLabel.text = @"副标题";
            cell.imageView.image = [UIImage imageNamed:@"1.jpg"];
            
            return cell;
        }
            break;
            
        case 2:
        case 3:
        {
#pragma mark - 知识点1 自定义cell
            /**
             * 系统自带4种cell样式, 往往不能满足开发需求, 可以自定义cell
             * 自定义cell类, 继承 UITableViewCell类
             */
            Mycell1 *mycell1 = [tableView dequeueReusableCellWithIdentifier:@"reuse2"];
            if (mycell1 == nil) {
                mycell1 = [[[Mycell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"resue2"] autorelease];
            }

            mycell1.mylable.text = [self.arr objectAtIndex:indexPath.row];
            mycell1.myImageView.image = [UIImage imageNamed:@"1.jpg"];

            return mycell1;
        }
            break;
            
            
        default:
        {
            /* 自定义cell2 */
            
            Mycell2 *mycell2 = [tableView dequeueReusableCellWithIdentifier:@"reuse3"];
            if (mycell2 == nil) {
                mycell2 = [[[Mycell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuse3"] autorelease];
            }
            
            return mycell2;
        }
            break;
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
